//
//  ZYHomeHeaderViewCell.m
//  YiLin
//
//  Created by Zyark on 2018/6/8.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYHomeHeaderView.h"
#import "UIButton+ImageTitleSpacing.h"
#import "ZYHome.h"

@interface ZYHomeHeaderView()

@property(nonatomic,strong) UIImageView *bgImageView;
/**
 TVOC
 */
@property(nonatomic,strong) UILabel *tvocLabel;

/**
 室温
 */
@property(nonatomic,strong) UILabel *roomTemperatureLabel;


/**
 pm2.5
 */
@property(nonatomic,strong) UILabel *pmLabel;

/**
 湿度
 */
@property(nonatomic,strong) UILabel *humidityLabel;

/**
 室内
 */
@property(nonatomic,strong) UILabel *roomLabel;

/**
 天气状态
 */
@property(nonatomic,strong) UILabel *statusLabel;
@property(nonatomic,strong) ZYChangeLanguage *language;
@end

@implementation ZYHomeHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _language = [ZYChangeLanguage sharedZYChangeLanguage];
        [self setup];
    }
    return self;
}

-(void)setup{
    _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_index_main_bg"]];
    _bgImageView.frame = self.bounds;
    [self addSubview:_bgImageView];
    
    CGFloat left = self.width * 0.17;
    _roomTemperatureLabel = [[UILabel alloc] init];
    _roomTemperatureLabel.font = [UIFont systemFontOfSize:60];
    _roomTemperatureLabel.textColor = RGBA(255, 255, 255, 1);
    _roomTemperatureLabel.textAlignment = NSTextAlignmentLeft;
    _roomTemperatureLabel.size = CGSizeMake(0.35 * self.width, 50);
    [self addSubview:_roomTemperatureLabel];
    if(ZYiPhone4_OR_4s || ZYiPhone5_OR_5c_OR_5s){
        _roomTemperatureLabel.top = self.height * 0.35;
    }else{
        _roomTemperatureLabel.top = self.height * 0.4;
    }
    _roomTemperatureLabel.left = left;
    
    _roomLabel = [self setupLabel];
    [self addSubview:_roomLabel];
    _roomLabel.left = _roomTemperatureLabel.left + 2;
    _roomLabel.top = _roomTemperatureLabel.bottom + 8;
    _roomLabel.width = _roomLabel.width *0.8;
    
    _statusLabel = [self setupLabel];
    [self addSubview:_statusLabel];
    _statusLabel.left = _roomLabel.left;
    _statusLabel.top = _roomLabel.bottom + 8;
    _statusLabel.width = _roomLabel.width;
    
    _humidityLabel = [self setupLabel];
    [self addSubview:_humidityLabel];
    _humidityLabel.top = _roomTemperatureLabel.top + 5;
    _humidityLabel.left = _roomLabel.right + 15;
    
    _tvocLabel = [self setupLabel];
    [self addSubview:_tvocLabel];
    _tvocLabel.left = _humidityLabel.left;
    _tvocLabel.bottom = _statusLabel.bottom;
    
    _pmLabel = [self setupLabel];
    [self addSubview:_pmLabel];
    _pmLabel.left = _humidityLabel.left;
    _pmLabel.centerY = _humidityLabel.bottom + (_tvocLabel.top - _humidityLabel.bottom) / 2;
}

-(void)setupTitle{
//    _roomLabel.text = [_language getStringByKey:LC_INDEX_MAIN_ROOM_LABEL];
//    _statusLabel.text = @"感觉舒适";
    if(!_home){
        _home = [[ZYHome alloc] init];
        _home.humidity = @"";
        _home.pmQuality = @"";
        _home.pmExponent = @"";
        _home.tvoc = @"";
        _home.temperature = @"";
    }
    _humidityLabel.text = [NSString stringWithFormat:@"%@:%@%%",[_language getStringByKey:LC_HOME_MAIN_HUMIDITY],_home.humidity];
    _pmLabel.text = [NSString stringWithFormat:@"PM2.5: %@ %@",_home.pmExponent,_home.pmQuality];
    _tvocLabel.text = [NSString stringWithFormat:@"TVOC: %@",_home.tvoc];
    CGFloat temperature =  [_home.temperature doubleValue];
    _roomTemperatureLabel.text = [NSString stringWithFormat:@"%.0f",temperature];
}

-(void)setHome:(ZYHome *)home{
    _home = home;
    [self setupTitle];
}

-(UILabel *)setupLabel{
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = RGBA(255, 255, 255, 1);
    label.textAlignment = NSTextAlignmentLeft;
    label.size = CGSizeMake(0.43*self.width, 14);
    return label;
}
@end
